{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e9da8b2a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>英语</th>\n",
       "      <th>计算机</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>P0456</td>\n",
       "      <td>小强</td>\n",
       "      <td>88</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>P1234</td>\n",
       "      <td>小美</td>\n",
       "      <td>85</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>P7890</td>\n",
       "      <td>大帅</td>\n",
       "      <td>28</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      学号  姓名  英语  计算机\n",
       "0  P0456  小强  88   90\n",
       "1  P1234  小美  85   85\n",
       "2  P7890  大帅  28   65"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "成绩表 = pd.read_csv(R'../data/第九周自建演示数据.csv')\n",
    "成绩表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "40045eba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>英语</th>\n",
       "      <th>计算机</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>P0456</td>\n",
       "      <td>小强</td>\n",
       "      <td>88</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>P1234</td>\n",
       "      <td>小美</td>\n",
       "      <td>85</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      学号  姓名  英语  计算机\n",
       "0  P0456  小强  88   90\n",
       "1  P1234  小美  85   85"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "成绩表.query('英语 > 60')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "86dbe570",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>英语</th>\n",
       "      <th>计算机</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>P0456</td>\n",
       "      <td>小强</td>\n",
       "      <td>88</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>P1234</td>\n",
       "      <td>小美</td>\n",
       "      <td>85</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      学号  姓名  英语  计算机\n",
       "0  P0456  小强  88   90\n",
       "1  P1234  小美  85   85"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "成绩表.query('英语 >= 85 and 计算机 >= 85')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1a036991",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>英语</th>\n",
       "      <th>计算机</th>\n",
       "      <th>总成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>P0456</td>\n",
       "      <td>小强</td>\n",
       "      <td>88</td>\n",
       "      <td>90</td>\n",
       "      <td>178</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>P1234</td>\n",
       "      <td>小美</td>\n",
       "      <td>85</td>\n",
       "      <td>85</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>P7890</td>\n",
       "      <td>大帅</td>\n",
       "      <td>28</td>\n",
       "      <td>65</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      学号  姓名  英语  计算机  总成绩\n",
       "0  P0456  小强  88   90  178\n",
       "1  P1234  小美  85   85  170\n",
       "2  P7890  大帅  28   65   93"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pandas中的常用函数\n",
    "\n",
    "成绩表['总成绩'] = 成绩表[['英语','计算机']].sum(axis=1)\n",
    "成绩表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ea1792df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>英语</th>\n",
       "      <th>计算机</th>\n",
       "      <th>总成绩</th>\n",
       "      <th>平均成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>P0456</td>\n",
       "      <td>小强</td>\n",
       "      <td>88</td>\n",
       "      <td>90</td>\n",
       "      <td>178</td>\n",
       "      <td>89.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>P1234</td>\n",
       "      <td>小美</td>\n",
       "      <td>85</td>\n",
       "      <td>85</td>\n",
       "      <td>170</td>\n",
       "      <td>85.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>P7890</td>\n",
       "      <td>大帅</td>\n",
       "      <td>28</td>\n",
       "      <td>65</td>\n",
       "      <td>93</td>\n",
       "      <td>46.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      学号  姓名  英语  计算机  总成绩  平均成绩\n",
       "0  P0456  小强  88   90  178  89.0\n",
       "1  P1234  小美  85   85  170  85.0\n",
       "2  P7890  大帅  28   65   93  46.5"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "成绩表['平均成绩'] = 成绩表[['英语','计算机']].mean(axis=1)\n",
    "成绩表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "384eab95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 3 entries, 0 to 2\n",
      "Data columns (total 6 columns):\n",
      " #   Column  Non-Null Count  Dtype  \n",
      "---  ------  --------------  -----  \n",
      " 0   学号      3 non-null      object \n",
      " 1   姓名      3 non-null      object \n",
      " 2   英语      3 non-null      int64  \n",
      " 3   计算机     3 non-null      int64  \n",
      " 4   总成绩     3 non-null      int64  \n",
      " 5   平均成绩    3 non-null      float64\n",
      "dtypes: float64(1), int64(3), object(2)\n",
      "memory usage: 276.0+ bytes\n"
     ]
    }
   ],
   "source": [
    "成绩表.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e6c588e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>英语</th>\n",
       "      <th>计算机</th>\n",
       "      <th>总成绩</th>\n",
       "      <th>平均成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>3.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>67.000000</td>\n",
       "      <td>80.000000</td>\n",
       "      <td>147.000000</td>\n",
       "      <td>73.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>33.808283</td>\n",
       "      <td>13.228757</td>\n",
       "      <td>46.936127</td>\n",
       "      <td>23.468063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>28.000000</td>\n",
       "      <td>65.000000</td>\n",
       "      <td>93.000000</td>\n",
       "      <td>46.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>56.500000</td>\n",
       "      <td>75.000000</td>\n",
       "      <td>131.500000</td>\n",
       "      <td>65.750000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>85.000000</td>\n",
       "      <td>85.000000</td>\n",
       "      <td>170.000000</td>\n",
       "      <td>85.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>86.500000</td>\n",
       "      <td>87.500000</td>\n",
       "      <td>174.000000</td>\n",
       "      <td>87.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>88.000000</td>\n",
       "      <td>90.000000</td>\n",
       "      <td>178.000000</td>\n",
       "      <td>89.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              英语        计算机         总成绩       平均成绩\n",
       "count   3.000000   3.000000    3.000000   3.000000\n",
       "mean   67.000000  80.000000  147.000000  73.500000\n",
       "std    33.808283  13.228757   46.936127  23.468063\n",
       "min    28.000000  65.000000   93.000000  46.500000\n",
       "25%    56.500000  75.000000  131.500000  65.750000\n",
       "50%    85.000000  85.000000  170.000000  85.000000\n",
       "75%    86.500000  87.500000  174.000000  87.000000\n",
       "max    88.000000  90.000000  178.000000  89.000000"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "成绩表.describe()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
